<template>
	<view>
		<swiper class="card-swiper square-dot" :indicator-dots="true" :circular="true"
		 :autoplay="true" interval="5000" duration="500" @change="cardSwiper" indicator-color="#8799a3"
		 indicator-active-color="#0081ff">
			<swiper-item v-for="(item,index) in info.photos" :key="index" :class="cardCur==index?'cur':''">
				<view class="swiper-item" @tap="previewImage(index)">
					<image :src="item" mode="aspectFit"></image>
				</view>
			</swiper-item>
		</swiper>
		<view class="cu-list menu card-menu margin-top">
			<view class="cu-item">
				<view class="content">
					<text class="cuIcon-title text-orange"></text>
					昵称: <text class="text-grey padding-left">{{info.nick_name}}</text>
				</view>
			</view>
			<view class="cu-item" v-if="info.avatar">
				<view class="content">
					<text class="cuIcon-title text-orange"></text>
					头像: 
					<view class="cu-avatar round lg margin-left" :style="[{ backgroundImage:'url(' + info.avatar + ')' }]"></view>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					<text class="cuIcon-title text-orange"></text>
					性别: <text class="text-grey padding-left">{{info.gender}}</text>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					<text class="cuIcon-title text-orange"></text>
					出生日期: <text class="text-grey padding-left">{{info.birthday}}</text>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					<text class="cuIcon-title text-orange"></text>
					所在位置: <text class="text-grey padding-left" v-if="info.region">
						{{info.region[0]}} {{info.region[1]}} {{info.region[2]}}
					</text>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					<text class="cuIcon-title text-orange"></text>
					身高: <text class="text-grey padding-left">{{info.height}}cm</text>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					<text class="cuIcon-title text-orange"></text>
					体重: <text class="text-grey padding-left">{{info.weight}}</text>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					<text class="cuIcon-title text-orange"></text>
					学历: <text class="text-grey padding-left">{{info.degree}}</text>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					<text class="cuIcon-title text-orange"></text>
					收入: <text class="text-grey padding-left">{{info.income}}</text>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					<text class="cuIcon-title text-orange"></text>
					小红书账号: <text class="text-red padding-left">{{info.red_book_id}}</text>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					<text class="cuIcon-title text-orange"></text>
					性格: <text class="text-grey padding-left">{{info.character}}</text>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					<text class="cuIcon-title text-orange"></text>
					爱好: <text class="text-grey padding-left">{{info.hobby}}</text>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					<text class="cuIcon-title text-orange"></text>
					手机号: <text class="text-red padding-left">{{info.phone}}</text>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					<text class="cuIcon-title text-orange"></text>
					对另一半期望: <text class="text-grey padding-left">{{info.other_expect}}</text>
				</view>
			</view>
			<view class="cu-item" v-if="info.status == 2">
				<view class="content">
					<text class="cuIcon-title text-orange"></text>
					未通过原因: <text class="text-red padding-left">{{info.audit_expect}}</text>
				</view>
			</view>
			<view class="padding flex flex-direction" v-if="info.status == 1">
				<button class="cu-btn bg-grey margin-tb-sm lg">已审核</button>
			</view>
			<view v-if="info.status == 0">
				<form>
					<view class="cu-form-group align-start">
						<view class="title text-red">不通过原因</view>
						<textarea maxlength="-1" @input="auditExpectInput" v-model="info.audit_expect"></textarea>
					</view>
				</form>
				<view class="padding flex flex-direction">
					<button class="cu-btn bg-green margin-tb-sm lg" @tap="auditAgree()">通过审核</button>
					<button class="cu-btn bg-red margin-tb-sm lg" @tap="auditFail()">拒绝通过</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { objectAuditInfo, auditAgree, auditFail } from '../../api/audit';
	export default {
		data() {
			return {
				cardCur: 0,
				dotStyle: false,
				info: {},
			};
		},
		onLoad(query) {
			// this.TowerSwiper('swiperList');
			// 初始化towerSwiper 传已有的数组名即可
			
			// 查询资料
			objectAuditInfo({account_id: query.id}).then(res => {
				if(res.info == undefined) {
					uni.navigateBack()
					return
				}
				this.info = res.info
				this.info.photos = [this.info.avatar,...this.info.photos]
			}).catch(err => {
				console.log(err)
				uni.navigateBack()
			});
		},
		methods: {
			previewImage(index) {
				uni.previewImage({
					current: index,
					indicator: "none",
					loop: false,
					urls: this.info.photos,
					longPressActions: {},
					sizeType: ['original']
				})
			},
			auditExpectInput(e) {
				// 审核原因
				this.info.audit_expect = e.detail.value
			},
			cardSwiper(e) {
				this.cardCur = e.detail.current
			},
			calculateAge(birthDateStr) {
				var birthDate = new Date(birthDateStr)
				var currentDate = new Date();
				var birthYear = birthDate.getFullYear();
				var birthMonth = birthDate.getMonth();
				var birthDayOfMonth = birthDate.getDate();
				var currentYear = currentDate.getFullYear();
				var currentMonth = currentDate.getMonth();
				var currentDayOfMonth = currentDate.getDate();
				 
				var age = currentYear - birthYear;
				if (currentMonth < birthMonth || (currentMonth == birthMonth && currentDayOfMonth < birthDayOfMonth)) {
				    age--;
				}
				return age;
			},
			auditAgree() {
				auditAgree({account_id: this.info.account_id}).then(res => {
					if(res != undefined && res.ok != undefined) {
						uni.showToast({ title: '提交成功', icon: 'none' });
						this.info.status = 1
					} else {
						uni.showToast({ title: '保存失败', icon: 'none' });
					}
				}).catch(err => {
					console.log(err)
				});
			},
			auditFail() {
				auditFail({account_id: this.info.account_id, audit_expect: this.info.audit_expect}).then(res => {
					if(res != undefined && res.ok != undefined) {
						uni.showToast({ title: '提交成功', icon: 'none' });
						this.info.status = 2
					} else {
						uni.showToast({ title: '保存失败', icon: 'none' });
					}
				}).catch(err => {
					console.log(err)
				});
			}
		}
	}
</script>

<style>
</style>